 // 得到图片原始的宽高
 export async function getImageSize(img) {
    if (img.naturalWidth) {
        // 适用于Firefox/IE9/Safari/Chrome/Opera浏览器
        return {
            width: img.naturalWidth,
            height: img.naturalHeight
        }
    } else {
        return await getImageSizeByUrl(img.src);
    }
}
// 使用Image对象获取图片真实宽高
function getImageSizeByUrl(url) {
    return new Promise(function (resolve, reject) {
        let image = new Image();
        image.onload = function () {
            resolve({
                width: image.width,
                height: image.height
            });
        };
        image.onerror = function () {
            reject(new Error('error'));
        };
        image.src = url;
    });
}


export function getImageInfo(data){
    var img =document.createElement("img")
    img.src=data
    // var img = document.getElementById("imgDom")
	getImageSize(img).then(res=>{
		console.log(res.width,res.height)
	})
}

export function fileToBlob(file, callback) {
    const type = file.type;
    const reader = new FileReader();
    reader.onload = function (evt) {
        const blob = new Blob([evt.target.result], { type });
        if (typeof callback === 'function') {
            callback(blob)
        } else {
            console.log("我是 blob:", blob);
        }
    };
    reader.readAsDataURL(file);
}
export function fileToBase64(file, callback){
    const reader = new FileReader();
    reader.onload = function(evt) {
        if(typeof callback === 'function') {
            callback(evt.target.result)
        } else {
            console.log("我是base64:", evt.target.result);
        }
    };
    reader.readAsDataURL(file);
}